// ==UserScript==
// @name         ce - getSheetCell
// @namespace    http://tako.tampermonkey.net/
// @version      0.1
// @description  getSheetCell
// @author       tako
// @match        *://*/*
// @run-at       context-menu
// @grant        none
// ==/UserScript==
(async function () {
  'use strict';
  // Your code here...
  const token = localStorage.getItem('console_TOKEN');
  const appId = 'c76ef194385e11eb9f43c90043244155';
  const formName = document.querySelector('.tfSearchForm .menu-search .ant-input').value;
  const sheetName = document.querySelector('.tfFilterDimension>div>span>input').value;
  const excelKey = document.querySelector('.tfSearchFormula .ant-input').value;

  // searchForm
  const bookId = await fetch(`/ce/form/searchForm?pageNum=1&pageSize=5&formName=${formName}`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'appId': appId,
      'Logintoken': token
    }
  }).then(response => {
    return response.json();
  }).then(data => {
    return data.data.bookInfos[0].bookId;
  });

  // querySheet
  const sheetId = await fetch('/ce/form/querySheet', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'appId': appId,
      'Logintoken': token
    },
    body: JSON.stringify({
      pageNum: 1,
      pageSize: 5,
      pageDimFilter: sheetName,
      bookIds: [bookId]
    })
  }).then(response => {
    return response.json();
  }).then(data => {
    return data.data.sheetInfos[0].sheetId;
  });

  // getSheetCell
  const sheetCell = await fetch(`/ce/test/getSheetCell?sheetId=${sheetId}&excelKey=${excelKey}`, {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'appId': appId,
      'Logintoken': token
    }
  }).then(response => {
    return response.json();
  }).then(data => {
    return data.cells;
  });

  console.log(sheetCell);
})();